package cn.ekuma.epos.inventory.model;

import cn.ekuma.epos.core.model.AbstractDLSaleDTOTableModel;
import com.openbravo.bean.sales.PosSharedProduct;
import com.openbravo.bean.viewbean.Product_V;
import com.openbravo.data.basic.BasicException;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;

public class PosSharedProductTableModel extends AbstractDLSaleDTOTableModel<PosSharedProduct>{
    
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		PosSharedProduct obj= objs.get(rowIndex);
		Product_V productInfo=obj.getProductInfo();
		if(productInfo==null){
			try {
				productInfo=dlSales.findProduct_VByProductId(obj.getProductId());
				
			} catch (BasicException e) {
				e.printStackTrace();
				productInfo=new Product_V();
			}
			obj.setProductInfo(productInfo);
		}
		if(columnIndex==0)
			return obj.getKeyStoke();
		switch(columnIndex-1){
		  case 0:
               return productInfo.getReference();
          case 1:
              return productInfo.getCode();
          case 2:
              return productInfo.getName();
          case 3:
              return productInfo.getSpecification();
          case 4:
              return Formats.CURRENCY.formatValue(productInfo.getM_dPriceSell());
          case 5:    
          	return Formats.CURRENCY.formatValue(productInfo.getM_dCustomerPrice());
          case 6:
         	 return productInfo.getM_sManufacturer();
          case 7:
         	 return productInfo.getM_origin();
          case 8:
         	 return productInfo.getM_iDurability();
          case 9:
         	 return productInfo.isCom()?"Y":" ";
          case 10:
         	 return productInfo.getM_quantity();
			
		}
		return null;
	}

	
	@Override
	public String[] getColumnNames() {
		return new String[]{
				    AppLocal.getIntString("label.keyStoke"),
		            AppLocal.getIntString("label.prodref"),
	        		AppLocal.getIntString("label.prodbarcode"),
	                AppLocal.getIntString("label.prodname"),
	                AppLocal.getIntString("label.prodSpecification"),
	                AppLocal.getIntString("label.prodpricesell"),
	                AppLocal.getIntString("label.baseCustomerPrice"),
	                AppLocal.getIntString("label.prodcut.m_sManufacturer"),
	                AppLocal.getIntString("label.product.origin"),
	                AppLocal.getIntString("label.product.m_iDurability"),
	                AppLocal.getIntString("label.prodaux"),
	                AppLocal.getIntString("label.product.quantity")
		    };
	}
}
